package com.ebupt.migu.music.config;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.hadoop.hbase.HbaseTemplate;

/**
 * hbase配置
 */
@Configuration
public class HbaseConfig {

    @Value("${hbase.ip}")
    private String ip;
    @Value("${hbase.port}")
    private String port;
    @Value("${hbase.znode}")
    private String node;

    @Bean
    public org.apache.hadoop.conf.Configuration getConfig() {
        org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", ip);
        conf.set("hbase.zookeeper.property.clientPort", port);
        conf.set("zookeeper.znode.parent", node);
        return conf;
    }

    @Bean
    public HbaseTemplate hbaseTemplate() {
        HbaseTemplate hbaseTemplate = new HbaseTemplate();
        hbaseTemplate.setConfiguration(getConfig());
        hbaseTemplate.setAutoFlush(true);
        hbaseTemplate.setEncoding("UTF-8");
        return hbaseTemplate;
    }

}
